package cn.itcast.users.controller;


import cn.itcast.result.Result;
import cn.itcast.users.dto.UserLoginDTO;
import cn.itcast.users.mapper.UserMapper;
import cn.itcast.users.pojo.User;
import cn.itcast.users.service.UserService;
import cn.itcast.users.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user/user")
@Api(tags = "C端用户相关接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    /**
     * 算出总用户量
     * 用于feign调用
     *
     * @param map
     * @return
     */
    @PostMapping("/feign/countByMap")
    Integer countByMap(@RequestBody Map<String, Object> map){
        return userMapper.countByMap(map);
    }




    /**
     * 根据用户信息，查询用户信息
     *
     */
    @GetMapping(value = "/one/{id}")
    public Result<User> one(@PathVariable("id")Long id){
        User user = userService.getById(id);
        return Result.success(user);
    }

    /**
     * c端用户登录
     *
     * @param dto
     * @return
     */
    @ApiOperation("c端用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDTO dto){
        UserLoginVO userLoginVO = userService.login(dto);

        return Result.success(userLoginVO);
    }

}